/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2012
 */

package com.tech15.pub.dao;

import java.util.HashMap;
import java.util.Map;

import javacommon.base.BaseHibernateDao;

import org.springframework.stereotype.Repository;

import cn.org.rapid_framework.page.Page;
import cn.org.rapid_framework.page.PageRequest;

import com.tech15.pub.model.OfficeItemsCollar;
import com.tech15.pub.vo.query.OfficeItemsCollarQuery;

@Repository
public class OfficeItemsCollarDao extends BaseHibernateDao<OfficeItemsCollar,Long>{

	public Class getEntityClass() {
		return OfficeItemsCollar.class;
	}
	
	public Page findByPageRequest(PageRequest<Map> pageRequest) {
		//XsqlBuilder syntax,please see http://code.google.com/p/rapid-xsqlbuilder
		// [column]为字符串拼接, {column}为使用占位符. 以下为图方便采用sql拼接,适用性能要求不高的应用,使用占位符方式可以优化性能. 
		// [column] 为PageRequest.getFilters()中的key
		String sql = "select t from OfficeItemsCollar t where 1=1 "
				+ "/~ and t.wpid = '[wpid]' ~/"
				+ "/~ and t.lyr = '[lyr]' ~/"
				+ "/~ and t.lyrq = '[lyrq]' ~/"
				+ "/~ and t.sl = '[sl]' ~/"
				+ "/~ and t.ffr = '[ffr]' ~/"
				+ "/~ and t.lybm = '[lybm]' ~/"
				+ "/~ and t.tjsj = '[tjsj]' ~/"
				+ "/~ and t.bz = '[bz]' ~/"
				+ "/~ order by [sortColumns] ~/";
		return pageQuery(sql,pageRequest);
	}
	
	public Page findPage(OfficeItemsCollarQuery query) {
		String sql = "select t.*,t1.mc as wpmc,t1.xh as wpxh,t1.gg as wpgg,t2.name as dataname from Office_Items_Collar t " +
				" left join Office_Items t1 on t.wpid=t1.id " +
				" left join pub_data t2 on t1.lb=t2.id where 1=1 "
			+ "/~ and t1.lb = [lb] ~/"
			+"/~ and t1.mc like '%[wpmc]%' ~/"
			+"/~ and t1.xh like '%[wpxh]%' ~/"
			+"/~ and t1.gg like '%[wpgg]%' ~/"
			+ "/~ and t.wpid = '[wpid]' ~/"
			+ "/~ and t.lyr = '[lyr]' ~/"
			+ "/~ and t.lyrq = '[lyrq]' ~/"
			+ "/~ and t.sl = '[sl]' ~/"
			+ "/~ and t.ffr = '[ffr]' ~/"
			+ "/~ and t.lybm = '[lybm]' ~/"
			+ "/~ and t.tjsj = '[tjsj]' ~/"
			+ "/~ and t.bz = '[bz]' ~/"
			+ "/~ and t.lyrmc like '%[lyrmc]%' ~/"
		  	+ "/~ and t.ffrmc like '%[ffrmc]%' ~/"
		  	+ "/~ and t.deptname like '%[deptname]%' ~/"
			+ "/~ order by [sortColumns] ~/";
		
		Map map = new HashMap();
		map.put("id", "Long");
		map.put("sl", "Long");
		map.put("lyrmc", "String");
		map.put("ffrmc", "String");
		map.put("deptname", "String");
		map.put("lyrq", "Timestamp");
		map.put("bz", "String");
		map.put("wpmc", "String");
		map.put("wpxh", "String");
		map.put("wpgg", "String");
		map.put("dataname", "String");
		return pageSqlQuery(sql, query, map, OfficeItemsCollar.class);
	}
	

}
